<?php

namespace func;

function imgToBase64($content, $type = 'png') {
    $img_base64 = '';
    $file_content = chunk_split(base64_encode($content)); // base64编码
    $img_base64 = 'data:image/' . $type . ';base64,' . $file_content;//合成图片的base64编码
    return $img_base64; //返回图片的base64
}




function curl_post($host,$data,$url) {
   $ch = curl_init();
   $res= curl_setopt ($ch, CURLOPT_URL,$url);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt ($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch,CURLOPT_HTTPHEADER,$host);
   $result = curl_exec ($ch);
   curl_close($ch);
   if ($result == NULL) {
       return 0;
   }
   return $result;
}